#include "employeeincome.h"
#include <QSqlQuery>
#include <QDateTime>
#include <QDebug>
#include <QObject>
#include <QThread>

const int EmployeeIncome::ID_COL = 0;
const int EmployeeIncome::NAME_COL = 1;
const int EmployeeIncome::DATE_COL = 2;
const int EmployeeIncome::SALARY_COL = 3;
const int EmployeeIncome::TIP_COL = 4;


EmployeeIncome::EmployeeIncome()
{
    this->id = -1;
    this->employeeId = -1;

}
int EmployeeIncome::getId() const
{
    return id;
}

void EmployeeIncome::setId(int value)
{
    id = value;
}
int EmployeeIncome::getEmployeeId() const
{
    return employeeId;
}

void EmployeeIncome::setEmployeeId(int value)
{
    employeeId = value;
}
double EmployeeIncome::getSalary() const
{
    return salary;
}

void EmployeeIncome::setSalary(double value)
{
    salary = value;
}
double EmployeeIncome::getTip() const
{
    return tip;
}

void EmployeeIncome::setTip(double value)
{
    tip = value;
}
long EmployeeIncome::getCreatedAt() const
{
    return createdAt;
}

void EmployeeIncome::setCreatedAt(long value)
{
    createdAt = value;
}
long EmployeeIncome::getModifiedAt() const
{
    return modifiedAt;
}

void EmployeeIncome::setModifiedAt(long value)
{
    modifiedAt = value;
}
QString EmployeeIncome::getName() const
{
    return name;
}

void EmployeeIncome::setName(const QString &value)
{
    name = value;
}







//void EmployeeIncome::updateEmployeeIncome(QStandardItemModel* model, QProgressDialog *progressDialog){

//    QModelIndex index;
//    QSqlQuery *sqlQuery = new QSqlQuery;
//    int row;
//    QString name, dateModel_str;
//    int id;
//    float salary;
//    float tip;


//    QDate dateModel;
//    for (row = 0; row < model->rowCount(); row++)
//    {
//        progressDialog->setValue(row);
//        index = model->index(row,ID_COL);
//        id = model->data(index).toInt();
//        if (id == 0) continue;
//        index = model->index(row,NAME_COL);
//        name = model->data(index).toString();

//        index = model->index(row,DATE_COL);
//        dateModel_str = model->data(index).toString();
//      //  qDebug()<< "dateModel_str:" + dateModel_str;

//        dateModel = QDate::fromString(dateModel_str,"MM-dd-yyyy");
//        QDateTime datetime(dateModel);
//        int timestamp_insr = datetime.toTime_t();

//      //  qDebug()<< "timestamp_insr:" + QString::number(timestamp_insr);
//        index = model->index(row,SALARY_COL);
//        salary = model->data(index).toFloat();

//        index = model->index(row,TIP_COL);
//        tip = model->data(index).toFloat();

//       // qDebug()<< QString::number(salary,'f',2);

//        QDateTime modifiedDateTime = QDateTime::currentDateTime();
//        int modifiedTimestamp = modifiedDateTime.toTime_t();

//        QString query_str;
//        query_str = "INSERT INTO income_worker (worker_id,salary,created_date, modified_date, tip) values("
//                + QString::number(id) + "," + QString::number(salary,'f',2) +"," + QString::number(timestamp_insr) + "," + QString::number(modifiedTimestamp) +
//                "," + QString::number(tip,'f',2) +
//                ")";
//        qDebug()<< query_str;
//        if (!sqlQuery->exec(query_str)){
//            query_str = "Update income_worker set salary="+QString::number(salary,'f',2)
//                    +", tip=" + QString::number(tip,'f',2)

//                    +", modified_date="
//                    +QString::number(modifiedTimestamp)
//                    + " where worker_id="
//                    +QString::number(id)+" AND created_date="
//                    +QString::number(timestamp_insr);
//          //  qDebug()<< query_str;
//            sqlQuery->exec(query_str);

//        }
//        QThread::msleep(10);

//    }
//}
